package com.icycandy.blogmover.hi2wp;

import java.util.ArrayList;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
 * 
 * @author icycandy
 */
public class Diary
{
	private int id;
	private String date;
	private String title;
	private String content;
	private String category;
	private ArrayList<Comment> comments;
	
	public Diary(int id, String date, String title, String content, String category, ArrayList<Comment> comments)
	{
		this.id = id;
		this.date = date;
		this.title = title;
		this.content = content;
		this.category = category;
		this.comments = comments;
	}
	
	public Element toXml()
	{
		Document document = DocumentHelper.createDocument();
		Element root = document.addElement("item");
		
		root.addNamespace("excerpt", "http://wordpress.org/export/1.0/excerpt/");
		root.addNamespace("content", "http://purl.org/rss/1.0/modules/content/");
		root.addNamespace("wfw", "http://wellformedweb.org/CommentAPI/");
		root.addNamespace("dc", "http://purl.org/dc/elements/1.1/");
		root.addNamespace("wp", "http://wordpress.org/export/1.0/");
		
		Element tmp = root.addElement("title");
		tmp.addText(title);
		
		tmp = root.addElement("link");
		
		tmp = root.addElement("pubDate");
		tmp.addText(date);
		
		tmp = root.addElement("dc:creator");
		tmp.addText("yourname");
		
		tmp = root.addElement("category");
		tmp.addCDATA(category);
		
		tmp = root.addElement("guid");
		tmp.addAttribute("isPermaLink", "false");
		
		tmp = root.addElement("description");
		
		tmp = root.addElement("content:encoded");
		tmp.addCDATA(content);
		
		tmp = root.addElement("wp:post_id");
		tmp.addText(Integer.toString(id));
		
		tmp = root.addElement("wp:post_date");
		tmp.addText(date);
		
		tmp = root.addElement("wp:post_date_gmt");
		tmp.addText(date);
		
		tmp = root.addElement("wp:comment_status");
		tmp.addText("open");
		
		tmp = root.addElement("wp:ping_status");
		tmp.addText("open");
		
		tmp = root.addElement("wp:post_name");
		tmp.addText(title);
		
		tmp = root.addElement("wp:status");
		tmp.addText("publish");
		
		tmp = root.addElement("wp:post_parent");
		tmp.addText("0");
		
		tmp = root.addElement("wp:menu_order");
		tmp.addText("0");
		
		tmp = root.addElement("wp:post_type");
		tmp.addText("post");
		
		tmp = root.addElement("wp:post_parent");
		tmp.addText(Integer.toString(id));
		
		tmp = root.addElement("wp:post_parent");
		tmp.addText(Integer.toString(id));
		
		tmp = root.addElement("wp:post_parent");
		tmp.addText(Integer.toString(id));
		
		if (null == comments || comments.size() == 0) return root;
		
		for (Comment comment : comments)
		{
			root.add(comment.toXml());
		}
		
		return root;
	}
	
	public static void main(String[] args)
	{
		
	}
}
